package com.fkdx.webman.controller;

import com.fkdx.dao.entity.PageResult;
import com.fkdx.service.DictService;
import com.fkdx.service.dto.*;
import org.springframework.web.bind.annotation.*;
import com.fkdx.common.dto.ResponseDTO;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 系统字典表controller
 */
@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private DictService dictService;

    @GetMapping("/list")
    public PageResult<DictQueryResp> getDictList(DictQueryReq req) {
        return dictService.getDictList(req);
    }

    @GetMapping("/getCode")
    public DictQueryResp getDictCode(String code) {
        return dictService.getDictCode(code);
    }


    @PostMapping("/getMap")
    public ResponseDTO<Map<String,DictQueryResp>> getDictMap(@RequestBody List<String> codes) {
        Map<String,DictQueryResp> m = dictService.getDictMap(codes);
        return ResponseDTO.buildSuccessDataResp(m);
    }

    @GetMapping("/form")
    public DictQueryResp getDictForm(Long id) {
        return dictService.getDictForm(id);
    }

    @GetMapping("/code")
    public ResponseDTO<String> getCode(String code) {
        String val = dictService.getCode(code);
        return ResponseDTO.buildSuccessDataResp(val);
    }

    @PostMapping("/save")
    public ResponseDTO<String> saveDictForm(@RequestBody @Valid DictReq req) {
        dictService.saveDictForm(req);
        return ResponseDTO.buildSuccessDataResp("ok");
    }

    @PostMapping("/remove")
    public ResponseDTO<String> removeDictList(@RequestBody Long[] id) {
        dictService.removeDictList(id);
        return ResponseDTO.buildSuccessDataResp("ok");
    }
}
